package com.eke.action.course;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.web.context.WebApplicationContext;

import com.eke.bean.ClassHour;
import com.eke.bean.Course;
import com.eke.bean.CourseChapters;
import com.eke.bean.CourseType;
import com.eke.service.CourseChapterSevice;
import com.eke.service.CourseSevice;
import com.jason.mvc.annotations.Ajax;
import com.jason.mvc.annotations.Namespace;
import com.jason.mvc.annotations.RequestMapping;

@Namespace("/courseChapter")
@Component("courseChapterAction")
@Scope(WebApplicationContext.SCOPE_REQUEST)
public class CourseChapterAction {
	@Resource
	private CourseChapterSevice courseChapterService;
	private Course course;
	private CourseType coursetype;
	private CourseChapters courseChapters;
	private ClassHour classHour;

	/**
	 * 添加课程章节
	 * 
	 */
	@RequestMapping("addCourseChapter")
	@Ajax(true)
	public boolean addCourseChapter() {
		courseChapters.setCourseId(course.getCourseId());
		int courseChapterId = courseChapterService.addCourseChapter(courseChapters);
		classHour.setCourseChapterId(courseChapterId);
		return courseChapterService.addClassHour(classHour);
	}

	/**
	 * 查询课程章节
	 * 
	 * @return map
	 */
	@RequestMapping("queryCourseChapter")
	@Ajax(true)
	public Map<String, Object> queryCourseChapter() {
		Map<String, Object> map = new HashMap<String, Object>();
		List<CourseChapters> courseChaptersList = courseChapterService.queryCourseChapter(course.getCourseId());
		List<ClassHour> classHoursList = new ArrayList<ClassHour>();
		for (CourseChapters courseChapters : courseChaptersList) {
			ClassHour cHour = courseChapterService.queryClassHours(courseChapters.getCourseChapterId());
			classHoursList.add(cHour);
		}
		map.put("courseChaptersList", courseChaptersList);
		map.put("classHoursList", classHoursList);
		return map;

	}

	/**
	 * 根据课时id查询课时详情
	 * 
	 * @param classHourId
	 *            课时ID
	 * @return {@link List}<{@link ClassHour}>
	 */
	@RequestMapping("queryClassHourByHourId")
	@Ajax(true)
	public Map<String, Object> queryClassHourByHourId() {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("classHour", courseChapterService.queryClassHourByHourId(classHour.getClassHourId()));
		return map;
	}

}
